package javaIO;


import java.io.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Logon implements Serializable {
    private Date date = new Date();
    private String username;
    private transient String password;

    public Logon(String name,String pass){
        this.username = name;
        this.password = pass;
    }

    @Override
    public String toString() {
        return "logon info: \n username: "+username+ "\n data: "+date+"\n password: "+password;
    }

    public static void main(String[] args) throws IOException,ClassNotFoundException,InterruptedException {
        Logon a = new Logon("Hulk","myLittlePony");
        System.out.println("login a = "+a);

        ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("logon.out"));
        o.writeObject(a);
        o.close();

        TimeUnit.SECONDS.sleep(1);

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("logon.out"));
        System.out.println("Recovering objct at "+new Date());
        a = (Logon)in.readObject();
        System.out.println("logon a = "+a);
    }
}
